package com.fourth.controller.api;

import com.fourth.dao.ZoneBusinessDao;
import com.fourth.service.ZoneBusinessService;
import com.fourth.vo.ZoneBusinessVo;
import com.ljx.entity.ZoneBusiness;
import com.ljx.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：lmy
 * @Date：2023/2/28 19:09
 */
@RestController
@RequestMapping("home/api/zoneBusiness")
public class ApiZoneBusinessController {
    @Autowired
    private ZoneBusinessService zoneBusinessService;

    @Autowired(required = false)
    private ZoneBusinessDao zoneBusinessDao;

    @PostMapping("managementZone/{currentPage}/{pageSize}")
    public Result managementZone(@PathVariable Integer currentPage, @PathVariable Integer pageSize,
                                 @RequestBody ZoneBusinessVo zoneBusinessVo){
        return zoneBusinessService.managementZone(currentPage,pageSize,zoneBusinessVo);

    }

    @PostMapping("selectBusiness")
    public Result selectBusiness(@RequestParam Integer currentPage, @RequestParam Integer pageSize,
                                 @RequestBody ZoneBusinessVo zoneBusinessVo){
        return zoneBusinessService.selectBusiness(currentPage,pageSize,zoneBusinessVo);
    }

    @GetMapping("changeStatus/{id}/{isDisable}")
    public Result changeStatus(@PathVariable String id,@PathVariable Integer isDisable){
        ZoneBusiness zoneBusiness = new ZoneBusiness();
        zoneBusiness.setId(id);
        zoneBusiness.setIsDisable(isDisable);
        int row = zoneBusinessDao.updateById(zoneBusiness);
        if (row == 1 ){
            return new Result(2000,"修改状态成功");
        }
        return new Result(5000,"修改状态失败");
    }

    @GetMapping("changePutaway")
    public Result changePutaway(@RequestParam String id,@RequestParam Integer putaway){
        ZoneBusiness zoneBusiness = new ZoneBusiness();
        zoneBusiness.setId(id);
        zoneBusiness.setPutaway(putaway);
        int row = zoneBusinessDao.updateById(zoneBusiness);
        if (row == 1 ){
            return new Result(2000,"修改上下架成功");
        }
        return new Result(5000,"修改上下架失败");
    }


    @GetMapping("changeSort/{id}/{sort}")
    public Result changeSort(@PathVariable String id,@PathVariable Integer sort){
        ZoneBusiness zoneBusiness = new ZoneBusiness();
        zoneBusiness.setId(id);
        zoneBusiness.setSort(sort);
        int row = zoneBusinessDao.updateById(zoneBusiness);
        if (row == 1 ){
            return new Result(2000,"修改排序成功");
        }
        return new Result(5000,"修改排序失败");
    }

    @GetMapping("deleteZoneBusiness/{id}")
    public Result deleteZoneBusiness(@PathVariable String id){
        int row = zoneBusinessDao.deleteById(id);
        if (row == 1 ){
            return new Result(2000,"删除成功");
        }
        return new Result(5000,"删除失败");
    }

    @GetMapping("addZoneBusiness")
    public Result addBusinessDetail(@RequestParam String bid,@RequestParam String zoneId){
        ZoneBusiness zoneBusiness =new ZoneBusiness();
        zoneBusiness.setBid(bid);
        zoneBusiness.setZoneId(zoneId);
        int row = zoneBusinessDao.insert(zoneBusiness);
        if (row == 1 ){
            return new Result(2000,"添加成功");
        }
        return new Result(5000,"添加失败");
    }
}
